"""
演示json数据 python字典的相互转换

"""
import json
# 准备列表，列表内的每一个元素都是字典，将其转换为json
data = [{"name":"张三","age":11},{"name":"李四","age":12},{"name":"王五","age":13}]
json_str = json.dumps(data, ensure_ascii=False)
print(type(json_str))
print(json_str)

# 准备字典，将字典转换为json
data = {"name": "周杰伦", "家乡": "台北"}
json_str = json.dumps(data,ensure_ascii=False)
print(json_str)

# 将json字符串转换为Python数据类型 [{k:v,k:v},{k:v,k:v}]
str = '[{"name": "张三", "age": 11}, {"name": "李四", "age": 12}, {"name": "王五", "age": 13}]'
list = json.loads(str)
print(list,type(list))
str = '{"name": "张三", "age": 11}'
dic = json.loads(str)
print(dic,type(dic))